#include "particulate.h"
#include<QtSql>
#include <string>
#include<iostream>
#include"dbutil.h"
using namespace std;
Particulate ::Particulate(QObject *parent):
    QObject(parent)
{}
void Particulate::updateParticulate(QString id,QString dust_degree_a,
                                    QString dust_degree_b,QString dust_degree_c)
{
    Dbutil db;
    QSqlDatabase data;
    data=db.connect();
    QSqlQuery update;
    string guoluid=id.toStdString();
    string dusta=dust_degree_a.toStdString();
    string dustb=dust_degree_b.toStdString();
    string dustc=dust_degree_c.toStdString();
    string sql = "UPDATE  particulate set dust_degree_a="+dusta+
            ",dust_degree_b="+dustb+",dust_degree_c="+dustc+" where id="+guoluid;
    const char *k = sql.c_str();
     bool success = update.exec(k);
    if(success)  {

         qDebug()<<"upadte success";
    }
    else qDebug()<< "fail";
    db.dbclose(data);
}

void  Particulate::selectParticulatebyid(QString id)
{
    Dbutil db;
    QSqlDatabase data;
    data=db.connect();
    QSqlQuery query;
    string gasid=id.toStdString();
    string sql="select *from particulate where id="+gasid;
    const char *k = sql.c_str();
    bool success = query.exec(k);
    if(success)  {
       query.next();
//         while(query.next()) qDebug()<<query.value().toString();
       dust_a=query.value(1).toString();
       dust_b=query.value(2).toString();
       dust_c=query.value(3).toString();

    }
    else qDebug()<< "fail";
db.dbclose(data);
}
QString Particulate::getdust_a()
{
    return dust_a;
}
QString Particulate::getdust_b()
{
    return dust_b;
}
QString Particulate::getdust_c()
{
    return dust_c;
}
